﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>方向条件-按照岗位计算</title>
    <link href="../../Scripts/easyUI145/themes/color.css" rel="stylesheet" />
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <!-- 引用通用的js文件. -->
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Comm/JScript.js" type="text/javascript"></script>
    <script src="../CCFlowEnum.js" type="text/javascript"></script>
    
    <script src="../Admin.js"></script>
    <script type="text/javascript" language="javascript">

        var operatorValue = "";
        var operatorValueT = "";

        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");
            var ifm = document.getElementById("stationFrame");
            ifm.height = document.documentElement.clientHeight - 67;

            InitPage();
           //    document.getElementById("TB_SpecOperPara").style.display='none';

            $("#Msg").html("");
        });
        //初始化数据.
        function InitPage() {
            //获取URL参数
            var nodeID = GetQueryString("FK_Node");
            var FK_MainNode = GetQueryString("FK_MainNode");
            var ToNodeID = GetQueryString("ToNodeID");

            //条件属性
            var mypk = FK_MainNode + "_" + ToNodeID + "_Dir_" + "Stas";
            
            var cond = new Entity("BP.WF.Template.Cond");
            cond.MyPK = mypk;
            cond.SetPKVal(mypk);
            cond.RetrieveFromDBSources();
            
            // 运算的值
            operatorValue = cond.OperatorValue.replace(/,/g, "@");
            if (cond.GetPara("orgEmps") != null)
                operatorValueT = cond.GetPara("orgEmps").replace(/&nbsp;&nbsp;/g, "@");


            //获取已指定操作员的岗位条件
            operatorValues = operatorValue.split("@");
            
            var operatorValueTs = operatorValueT.split("@");


            ////根据用户的信息，判断是否启用那个设置工具。
            var user = new WebUser();
            $("#AdminModel").hide();
            $("#OrgModel").hide();
            

            if (user.FK_Dept == 0) {
                /*调用通用的.*/
                $("#AdminModel").show();
                var showCondition = InitStation(operatorValues);
                document.getElementById("emps").innerHTML = showCondition[2];
                document.getElementById("stations").innerHTML = "合计:(<font color=red>" + showCondition[0] + "</font>)条" + showCondition[1];


            } else {
                
                /*调用集团模式的.*/
                $("#OrgModel").show();
                var showCondition = InitStation(operatorValues);
                var showConditionT = InitStation(operatorValueTs);
                $("#groupCount").html(showCondition[0])
                $("#groupStations").html(showCondition[1])
                $("#groupEmps").html(showCondition[2])
                $("#orgCount").html(showConditionT[0])
                $("#orgStations").html(showConditionT[1])
                $("#orgEmps").html(showConditionT[2])
                var count = showCondition[0] + showConditionT[0];
                document.getElementById("emps").innerHTML = showCondition[2] + showConditionT[2];
                document.getElementById("stations").innerHTML = "合计:(<font color=red>" + count + "</font>)条" + showCondition[1] + showConditionT[1];
            }

            //TODO 条件参数
            //var atpara = cond.AtPara;
            //if (atpara != "") {

            //    var initDDL_SpecOperWay = atpara.split("@")[2].split("=")[1];
            //    document.getElementById("initDDL_SpecOperWay").value = initDDL_SpecOperWay;
            //    document.getElementById("DDL_SpecOperWay").value = initDDL_SpecOperWay;

            //    var initTB_SpecOperPara = atpara.split("@")[3].split("=")[1];
            //    document.getElementById("TB_SpecOperPara").value = initTB_SpecOperPara;
            //    if (initDDL_SpecOperWay != 0) {
            //        document.getElementById("TB_SpecOperPara").disabled = "";
            //    }
            //    document.getElementById("initTB_SpecOperPara").value = initTB_SpecOperPara;
            //    $("#span" + initDDL_SpecOperWay).css("display", "inline-block");
            //    $("#span" + initDDL_SpecOperWay).siblings().css("display", "none");
            //}

            //条件参数 end
            //end
            var currCondStation = null;


            //调用公共类库的方法:执行批量主表赋值
            if (currCondStation != null)
                GenerFullAllCtrlsVal(currCondStation);
        }

        function InitStation(CheckStations) {

            var showCondition = new Array();
            var html = "";
            var emps = "";
            var count = 0;
            for (var i = 0; i < CheckStations.length; i++) {
                if (CheckStations[i] != "") {

                    var en = new Entity("BP.Port.Station", CheckStations[i]);
                    html += "&nbsp;&nbsp;&nbsp;" + en.Name;
                    count++;
                    emps += CheckStations[i] + ",";
                }
            }
            showCondition[0] = count;
            showCondition[1] = html;
            showCondition[2] = emps;
            return showCondition;
        }

        //设置本组织岗位.
        function SetAdminStations() {

            var user = new WebUser();

            OpenNodStationGroup("", 1);
        }
        //设置集团岗位.
        function SetGroupStations() {
            var user = new WebUser();
            OpenNodStationGroup(user.GroupNo, 2);
        }
        //设置本组织岗位.
        function SetOrgStations() {
            var user = new WebUser();
            OpenNodStationGroup(user.FK_Dept, 3);
        }

        function OpenNodStationGroup(orgNo, selectType) {
            var emps = $("#emps").html();
            if (orgNo == undefined)
                orgNo = 0;
            var url = "SelectStation.htm?OrgNo=" + orgNo + "&FK_Node=" + GetQueryString("FK_Node") + "&emps=" + emps + "&SelectType=" + selectType;
            document.getElementById("stationFrame").style.width = "100%";
            document.getElementById("stationFrame").src = url;
            
            $("#win").window("open");

        }

        function Btn_Delete_Click() {

            if (window.confirm('您确定要删除吗？') == false)
                return;
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("FK_Node", GetQueryString("FK_Node"));
            
            handler.AddPara("ToNodeID", GetQueryString("ToNodeID"));
            handler.AddPara("DirType", GetQueryString("DirType"));
            handler.AddPara("CondType", GetQueryString("CondType"));
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("CondByStation_Delete");
            window.location.href = window.location.href;

        }

        function Btn_Save_Click() {

            var param = location.href.split("?")[1];

            //var checkBoxIDs = GenerCheckIDs(); //获得所有的 checkBox ID传入到后台去,用于解决checkbox控件，在没有被选择的时候，没有值的问题。
            //获取所有选中的checkbox
            var emps = document.getElementById("emps").innerHTML;
            var orgEmps = "";
            var user = new WebUser();
            if (user.FK_Dept != 0) {
                emps = document.getElementById("groupEmps").innerHTML;
                orgEmps = document.getElementById("orgEmps").innerHTML;
            }

            var frmData = $("#cc").serialize();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("FK_Node", GetQueryString("FK_Node"));
            handler.AddPara("emps", emps);
            handler.AddPara("orgEmps", orgEmps);
            handler.AddPara("FK_MainNode", GetQueryString("FK_MainNode"));
            handler.AddPara("ToNodeID", GetQueryString("ToNodeID"));
            handler.AddPara("DirType", GetQueryString("DirType"));
            handler.AddPara("CondType", GetQueryString("CondType"));
            handler.AddPara("CondOrAnd", GetQueryString("CondOrAnd"));
            handler.AddFormData()
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("CondByStation_Save");

            alert("保存成功");
            Back();

        }
       

        function getChidrenValue(data) {
    
            $('#win').window('close'); // close a window
            if (data[3] == "1") {

                document.getElementById("stations").innerHTML = "合计:(<font color=red>" + data[2] + "</font>)条" + data[1];
                document.getElementById("emps").innerHTML = data[0];
            }
            if (data[3] == "2") {
                $("#groupEmps").html(data[0]);
                $("#groupStations").html(data[1]);
                $("#groupCount").html(data[2]);
                
                var orgCount = $("#orgCount").html();
                var orgStations = $("#orgStations").html();
                var orgEmps = $("#orgEmps").html();
                var count = 0;
                if (orgCount == null || orgCount == "") orgCount = 0;
                if (data[2] == null || data[2] == "") data[2] = 0;
                count = parseInt(orgCount) + parseInt(data[2]);
                document.getElementById("stations").innerHTML = "合计:(<font color=red>" + count + "</font>)条" + orgStations + data[1];
                document.getElementById("emps").innerHTML = orgEmps + data[0];
            }

            if (data[3] == "3") {
                $("#orgEmps").html(data[0]);
                $("#orgStations").html(data[1]);
                $("#orgCount").html(data[2]);
                var groupCount = $("#groupCount").html();
                var groupStations = $("#groupStations").html();
                var groupEmps = $("#groupEmps").html();
                var count = 0;

                if (groupCount == null || groupCount == "")
                    groupCount = 0;

                if (data[2] == null || data[2] == "")
                    data[2] = 0;

                count = parseInt(groupCount) + parseInt(data[2]);
                document.getElementById("stations").innerHTML = "合计:(<font color=red>" + count + "</font>)条" + groupStations + data[1];
                document.getElementById("emps").innerHTML = groupEmps + data[0];
            }

            //获取URL参数
            var nodeID = GetQueryString("FK_Node");
            
            var ToNodeID = GetQueryString("ToNodeID");

            //条件属性.
            //var mypk = FK_MainNode + "_" + ToNodeID + "_Dir_" + "Stas";
            //var cond = new Entity("BP.WF.Template.Cond");
            //cond.MyPK = mypk;
            //cond.RetrieveFromDBSources();

            //cond.OperatorValue = data[0];
            //cond.OperatorValueT = data[1];
            //cond.Save();
        }

         //返回.
        function Back() {
            var url = window.location.href;
            if (GetQueryString("CondOrAnd") == null)
                url = url.replace('CondStation.htm', 'List.htm');
            else {
                url = url.replace('CondStation.htm', 'DirList.htm');
                url = url.replace('&CondOrAnd=' + GetQueryString("CondOrAnd"),'  ');
            }
            window.location.href = url;
        }
    </script>

    <style type="text/css">
        ul .cond li {
            display: none;
            line-height: 50px;
        }

            ul .cond li .active {
                display: block;
            }

        select {
            display: inline-block;
            width: 200px;
        }

        #Btn_Save1,#Btn_Delete,#Btn_Back {
            border: 0px solid #031f5d;
            background-color:#fff;
            color: #031f5d;
        }
        #Btn_Save1:hover,#Btn_Delete:hover,#Btn_Back:hover {
            border: 0;
            background: #1d7dd4;
            color:#fff;
            cursor:pointer;
            border: 1px solid #1d7dd4;
        }
        .lbls span {
            width: 80px;
        }
    </style>
</head>
<body>
    <form id="cc">
        <div id="bar" class="cs-tr cs-bar">
            <input id="button" style="background-color:#62CAE3" type=button value="保存" onclick="Btn_Save_Click()" />
            <!--<input id="Btn_Delete" type=button value="删除"  onclick="Btn_Delete_Click()" />-->
            <input id="button" style="background-color:#62CAE3" type=button value="返回" onclick="Back()" />
        </div>

        <fieldset id="AdminModel">
            <legend>设置(超级管理员)</legend>
            <ul>
                <li><a href="javascript:OpenOld()">设置/更改岗位</a></li>

            </ul>
        </fieldset>
        <fieldset id="OrgModel">
            <legend>设置（组织管理员）</legend>
            <ul>
                <li> <a href="javascript:SetGroupStations()">设置集团岗位</a> </li>
                <li> <a href="javascript:SetOrgStations()">设置本组织岗位</a> </li>
            </ul>
        </fieldset>
        <fieldset>
            <legend>已经设置的岗位</legend>
            <br />
            <div id="stations"></div>

        </fieldset>

        <label id="emps" style="display:none"></label>
        <label id="groupCount" style="display:none"></label>
        <label id="orgCount" style="display:none"></label>
        <label id="groupStations" style="display:none"></label>
        <label id="orgStations" style="display:none"></label>
        <label id="groupEmps" style="display:none"></label>
        <label id="orgEmps" style="display:none"></label>
        <br />
        
        <fieldset>

            指定的操作员：<select id="DDL_SpecOperWay" name="DDL_SpecOperWay" onchange="selChange()">
                <option selected="selected" value="0">当前操作员</option>
                <option value="1">指定节点的操作员</option>
                <option value="2">指定表单字段作为操作员</option>
                <option value="3">指定操作员编号</option>
            </select>
            <input type="hidden" name="initDDL_SpecOperWay" id="initDDL_SpecOperWay" value=" " />
            <input type="hidden" name="initTB_SpecOperPara" id="initTB_SpecOperPara" value=" " />
            <br />
            <br />
            <span class="lbls">
                <span id="span0">参数：</span>
                <span id="span1" style="display: none">节点编号：</span>
                <span id="span2" style="display: none">表单字段：</span>
                <span id="span3" style="display: none">操作员编号：</span>
            </span>
            <input id="TB_SpecOperPara" name="TB_SpecOperPara" type="text" disabled="disabled" style="width: 200px;" />&nbsp;&nbsp;多个值请用英文“逗号”来分隔。

        </fieldset>

        <!--隐藏的文本框-->
        <div id="win" class="easyui-window" title="绑定岗位" style="width:600px;height:400px" closed="true"
             data-options="iconCls:'icon-save',modal:true">

            <div data-options="region:'north',title:'North Title',split:true" style="height:50px;">
                <iframe id="stationFrame" src="#" scrolling="no" frameborder="0"></iframe>

            </div>
        </div>

    </form>
</body>
</html>
